package com.conversationboard.batch.jobs.subscriptions;

import java.io.FileNotFoundException;
import java.io.IOException;
import java.sql.SQLException;
import java.util.Date;

import javax.mail.MessagingException;
import javax.naming.NamingException;
import javax.xml.transform.TransformerConfigurationException;
import javax.xml.transform.TransformerException;

import org.quartz.Job;
import org.quartz.JobExecutionContext;
import org.quartz.JobExecutionException;

import com.conversationboard.logger.LogMessageType;
import com.conversationboard.logger.Logger;
import com.conversationboard.subscriptions.ProcessBoardSubscriptions;

public class SubscriptionsJob implements Job {

	public void execute(JobExecutionContext context) throws JobExecutionException {

		try {

			Logger.log(new Date(), "Starting subscriptions job", null, LogMessageType.SYSTEM);
			long startTime = System.currentTimeMillis();

			ProcessBoardSubscriptions subscriptions = new ProcessBoardSubscriptions();
			subscriptions.processSubscriptions();
			
			long timeTaken = System.currentTimeMillis() - startTime;
			Logger.log(new Date(), "Subscriptions Job took: " + timeTaken + " milliseconds", null, LogMessageType.DEBUG);

		} catch (TransformerConfigurationException e) {
			throw new JobExecutionException(e);
		} catch (FileNotFoundException e) {
			throw new JobExecutionException(e);
		} catch (SQLException e) {
			throw new JobExecutionException(e);
		} catch (TransformerException e) {
			throw new JobExecutionException(e);
		} catch (MessagingException e) {
			throw new JobExecutionException(e);
		} catch (NamingException e) {
			throw new JobExecutionException(e);
		} catch (IOException e) {
			throw new JobExecutionException(e);
		}

	}

}
